﻿using System.Collections.Generic;
using NUnit.Framework;

namespace ExtensionMethodExtravaganza.Tests
{
	[TestFixture]
	public class GenericIEnumerableExtensionTests
	{
		[Test]
		public void FindTest()
		{
			var letters = new[] { "a", "b", "c" };
			var numbers = new[] { 1, 2, 3 };

			Assert.AreEqual("b", letters.Find(l => l == "b"));
			Assert.IsNull(letters.Find(l => l == "z"));
			Assert.AreEqual(2, numbers.Find(n => n == 2));
			Assert.AreEqual(0, numbers.Find(n => n == 10));
		}

		[Test]
		public void ForEachTest()
		{
			var a = new object();
			var b = new object();
			var c = new object();

			var list = new List<object>();

			new[] { a, b, c }.ForEach(o => list.Add(o));

			Assert.AreEqual(a, list[0]);
			Assert.AreEqual(b, list[1]);
			Assert.AreEqual(c, list[2]);
		}
	}
}
